package jcataloger.resources;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * This class is used for internationalize the project. All text in the project are read <br>
 * from a resource file. This class is used to read the requested text.
 * @author sekobey
 *
 */
public class Messages {
	private static final String BUNDLE_NAME = "jcataloger.resources.messages";

	private static ResourceBundle RESOURCE_BUNDLE = ResourceBundle
			.getBundle(BUNDLE_NAME, new Locale("en","US"));

	private Messages() {
	}

	public static void setLocale(String language, String country) {
		RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, new Locale(language, country));
	}
	
	public static String getString(String key) {
		try {
			return RESOURCE_BUNDLE.getString(key);
		} catch (MissingResourceException e) {
			return '!' + key + '!';
		}
	}
	
	public static String getString(String key, String param1) {
		try {
			String value = RESOURCE_BUNDLE.getString(key);
			return value.replace("{0}", param1);
		} catch (MissingResourceException e) {
			return '!' + key + '!';
		}
		
	}
	
	public static String getString(String key, String param1, String param2) {
		String value = getString(key, param1);
		return value.replace("{1}", param2);
	}
	
	public static String getString(String key, String param1, String param2, String param3) {
		String value = getString(key, param1);
		return value.replace("{2}", param3);
	}
	
}
